package com.example.demo99.Service.Impl;

import com.example.demo99.Domian.User;
import com.example.demo99.Mapper.UserMapper;
import com.example.demo99.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServicelmpl implements UserService {
    @Autowired
    private UserMapper userMapper;
//    @Override
//    public List<User> select(String User) {
//       return userMapper.selectUser(User);
//    }

    @Override
    public User al(int id) {
        return userMapper.al(id);
    }

    @Override
    public String delete(Integer id) {
        int result = userMapper.delete(id);
        if (result == 0) {
            return "删除失败";
        }else {
            return "删除成功";
        }


    }

    @Override
    public String edit(User user) {
        if (user.getId() == 0) {
            int result = userMapper.add(user.getClass_name(), user.getXueyuan(), user.getNumber());
            if (result == 0) {
                return "新增失败";
            } else {
                return "新增成功";

            }
        } else {
            int result = userMapper.edit(user.getId(), user.getClass_name(), user.getXueyuan(), user.getNumber());
            if (result == 0) {
                return "编辑失败";
            } else {
                return "编辑成功";
            }
        }
    }

    @Override
    public List<User> getAll(String xueyuan) {
       return userMapper.getAll(xueyuan);
    }

}
